package com.sinux.sshUser.entity;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
@Table(name = "department")
@DynamicInsert(true)
@DynamicUpdate(true)
public class Department {

	private String id; // 部门ID
	private String text;// 部门名称
	private String depid;
	private List children=new ArrayList();
	
	@JsonIgnore
	private Set<Role> roles = new HashSet<Role>();
	@JsonIgnore
	private Set<User> users = new HashSet<User>();

	@Id
	@Column(name = "de_id", unique = true,nullable = false, length = 64)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(name = "de_name", nullable = false, length = 64)
	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}
	
	@Column(name = "de_pid", nullable = false, length = 64)
	public String getDepid() {
		return depid;
	}

	public void setDepid(String depid) {
		this.depid = depid;
	}
	
	@Transient
	public List getChildren() {
		return children;
	}

	public void setChildren(List children) {
		this.children = children;
	}

	@ManyToMany(fetch=FetchType.EAGER)
	@JoinTable(name="re_role_department",joinColumns={
			@JoinColumn(name="de_id",nullable=false,updatable=false)},inverseJoinColumns={
					@JoinColumn(name="ro_id",nullable=false,updatable=false)})
	public Set<Role> getRoles() {
		return roles;
	}
	
	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}
	
	@ManyToMany(fetch=FetchType.EAGER)
	@JoinTable(name="re_user_department",joinColumns={
			@JoinColumn(name="de_id",nullable=false,updatable=false)},inverseJoinColumns={
					@JoinColumn(name="u_id",nullable=false,updatable=false)})
	public Set<User> getUsers() {
		return users;
	}

	public void setUsers(Set<User> users) {
		this.users = users;
	}
	
	

}
